package tpdisenio2009.model.dao;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.LogicalExpression;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import tpdisenio2009.model.HibernateUtils;
import tpdisenio2009.model.beans.Administrator;


public class AdministratorDAO extends AbstractDAO<Administrator> {

    @Override
    public Class<Administrator> getPersistentClass() {
        return Administrator.class;
    }

    public Administrator getAdminByDocument( String document, String documentType ) {
        Session session = HibernateUtils.getCurrentSession();

        Criterion documentCriterion = Property.forName( "document" ).eq( document );
        Criterion documentTypeCriterion = Property.forName( "documentType" ).eq( documentType );

        LogicalExpression documentExpression = Restrictions.and( documentCriterion, documentTypeCriterion );

        Criteria criteria = session.createCriteria( Administrator.class ).add( documentExpression );

        return (Administrator) criteria.uniqueResult();
    }

}
